package com.shouxue.switchbutton;

import android.os.Bundle;
import android.widget.TextView;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });

        SlideSwitch slideSwitch = findViewById(R.id.sw);
        TextView textView = findViewById(R.id.tv);
        slideSwitch.setSelected(true);
        slideSwitch.setOnClickListener(v -> {
            if (slideSwitch.isSelected()) {
                slideSwitch.setSelected(false);
                textView.setText("这是开关按钮：按钮关");
            } else {
                slideSwitch.setSelected(true);
                textView.setText("这是开关按钮：按钮开");
            }
        });
    }
}